/* 
 * File: itemstablemodel.cpp
 * Project: QTimeTracker
 * Author: Steve Sindelar, http://stevesindelar.cz
 * Licence: NewBSD licence.
 */

#include "itemstablemodel.h"

using namespace Ui;

//------------------------------------------------------------------------------//
//------------------------ Name column -----------------------------------------//

ItemsTableModel::NameColumn::NameColumn(ItemsTableModel* model)
{
    this->model = model;
}

QString ItemsTableModel::NameColumn::getHeader() const
{
    return tr("Name");
}

QVariant ItemsTableModel::NameColumn::getDataForEditRole(const QModelIndex &index) const
{
    return this->model->getItems()[index.row()]->name;
}

QVariant ItemsTableModel::NameColumn::getDataForDisplayRole(const QModelIndex &index) const
{
    return this->model->getItems()[index.row()]->name;
}

bool ItemsTableModel::NameColumn::setData(const QModelIndex &index, const QVariant &value) const
{
    this->model->getItems()[index.row()]->name = value.toString();
    return true;
}

Qt::ItemFlags ItemsTableModel::NameColumn::getFlags(const QModelIndex & index) const
{
    return Qt::ItemIsEditable | Qt::ItemIsSelectable | Qt::ItemIsEnabled;
}

//------------------------------------------------------------------------------//
//------------------------ Length column -----------------------------------------//

ItemsTableModel::LengthColumn::LengthColumn(ItemsTableModel* model)
{
    this->model = model;
}

QString ItemsTableModel::LengthColumn::getHeader() const
{
    return tr("Length");
}

QVariant ItemsTableModel::LengthColumn::getDataForEditRole(const QModelIndex &index) const
{
    return this->model->getItems()[index.row()]->getLength().toString();
}

QVariant ItemsTableModel::LengthColumn::getDataForDisplayRole(const QModelIndex &index) const
{
    return this->model->getItems()[index.row()]->getLength().toString();
}

bool ItemsTableModel::LengthColumn::setData(const QModelIndex &index, const QVariant &value) const
{
    return true;
}

Qt::ItemFlags ItemsTableModel::LengthColumn::getFlags(const QModelIndex & index) const
{
    return /*Qt::ItemIsEditable |*/ Qt::ItemIsSelectable | Qt::ItemIsEnabled;
}

//------------------------------------------------------------------------------//
//------------------------ Length column -----------------------------------------//

ItemsTableModel::NoteColumn::NoteColumn(ItemsTableModel* model)
{
    this->model = model;
}

QString ItemsTableModel::NoteColumn::getHeader() const
{
    return tr("Note");
}

QVariant ItemsTableModel::NoteColumn::getDataForEditRole(const QModelIndex &index) const
{
    return this->model->getItems()[index.row()]->note;
}

QVariant ItemsTableModel::NoteColumn::getDataForDisplayRole(const QModelIndex &index) const
{
    return this->model->getItems()[index.row()]->note;
}

bool ItemsTableModel::NoteColumn::setData(const QModelIndex &index, const QVariant &value) const
{
    this->model->getItems()[index.row()]->note = value.toString();
    return true;
}

Qt::ItemFlags ItemsTableModel::NoteColumn::getFlags(const QModelIndex & index) const
{
    return Qt::ItemIsEditable | Qt::ItemIsSelectable | Qt::ItemIsEnabled;
}
